{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `FileSelector` widget allows browsing the filesystem on the server and selecting one or more files in a directory.\n",
    "\n",
    "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](../../how_to/interactivity/index.md). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](../../how_to/links/index.md) or [how to use them as part of declarative UIs with Param](../../how_to/param/index.md).\n",
    "\n",
    "#### Parameters:\n",
    "\n",
    "For details on other options for customizing the component see the [layout](../../how_to/layout/index.md) and [styling](../../how_to/styling/index.md) how-to guides.\n",
    "\n",
    "##### Core\n",
    "\n",
    "* **`directory`** (str): The directory to browse (cannot access files above this directory).\n",
    "* **`file_pattern`** (str, default='*'): A glob-like query expression to limit the displayed files.\n",
    "* **`only_files`** (bool, default=False): Whether to only allow selecting files.\n",
    "* **`refresh_period`** (int, default=None): If set to non-None value indicates how frequently to refresh the directory contents in milliseconds.\n",
    "* **`root_directory`** (str, default=None): If set to non-None value overrides directory parameter as the root directory beyond which users cannot navigate.\n",
    "* **`show_hidden`** (bool, default=False): Whether to show hidden files and directories (starting with a period).\n",
    "* **`value`** (list[str]): A list of file names.\n",
    "\n",
    "##### Display\n",
    "\n",
    "* **`name`** (str): The title of the widget\n",
    "\n",
    "___"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `FileSelector` widget allows exploring the specified directory on the server's filesystem and any directories contained within it. The widget consists of the navigation bar with a number of buttons and the address bar:\n",
    "\n",
    "* Back (`◀`): Goes to the previous directory\n",
    "* Forward (`▶`): Returns to the last directory after navigating back\n",
    "* Up (`⬆`): Goes one directory up\n",
    "* Address bar: Display the directory to navigate to\n",
    "* Enter (`⬇`): Navigates to the directory in the address bar\n",
    "* Reload (`↻`): Reloads the contents of the current directory\n",
    "\n",
    "The actual file selector displays the contents of the current directory, to navigate to a subfolder either double-click on it or click on a directory in the file selector and then hit the down arrow (`⬇`) in the navigation bar. Files and folders may be selected by selecting them in the browser on the left and moving them to the right with the arrow buttons:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "files = pn.widgets.FileSelector('~')\n",
    "\n",
    "files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get the currently selected files simply access the `value` parameter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "files.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Remote filesystem\n",
    "\n",
    "By using the power of [`fsspec`](https://filesystem-spec.readthedocs.io/en/latest/) we can connect to remote filesystems. In the example below we use the `s3fs` package to connect to a remote S3 server"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import s3fs\n",
    "\n",
    "fs = s3fs.S3FileSystem(anon=True)\n",
    "\n",
    "s3_files = pn.widgets.FileSelector(directory=\"s3://datasets.holoviz.org\", fs=fs)\n",
    "s3_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s3_files.value"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
